// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

const db = cloud.database()
const todos = db.collection('orders_data')

// 云函数入口函数
exports.main = async (event) => {
  const wxContext = cloud.getWXContext()
  const {guestName, guestNumber, guestGender, appointTime, goodsTit, goodsPrice, orderState, goodsImg, creatTime} = event

  const res = await todos.add({
    data: {
      guestName,
      guestNumber,
      guestGender,
      appointTime,
      goodsTit,
      goodsPrice,
      goodsImg,
      orderState,
      creatTime,
      sortTime: new Date().getTime(),
      openid: wxContext.OPENID
    }
  })
  
  return res

}